package com.pentalog.ginet;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.pentalog.ginet.domain.Counter;
import com.pentalog.ginet.domain.Stock;
import com.pentalog.util.HibernateUtil;

/**
 * Hello world!
 * 
 */
public class TestCounter {
	public static void main(String[] args) {		
		Session session = null;
		Transaction tx = null;
		try {
			session = HibernateUtil.getSessionFactory().openSession();
			tx = session.beginTransaction();
			Counter counter = new Counter();
			Integer i = new Integer("1");
			counter.setIvalue(i);
			session.save(counter);
			session.flush();
			tx.commit();
			Counter counter2 = (Counter) session.load(Counter.class, counter.getId());
			System.out.println(counter.getId() + " : " + counter.getIvalue().intValue());
			System.out.println(counter2.getId() + " : "+ counter2.getIvalue().intValue());
			System.out.println("\n\n----------> OK" + System.getProperty("user.dir"));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("\n\n----------> false");
		} finally {
			// Actual contact insertion will happen at this step
			session.flush();
			session.close();

		}
	}
}
